package sort.algorithm;

import sort.record.Record;
import sort.record.Records;

public class SelectionSort extends Sorter {

	@Override
	public Records sort(Records records) {
		for(int i=0;i < records.size();i++)
		{
			int min = i ;
			int j;
			for(j=i+1; j<records.size() ;j++) {
				if(records.get(min).getKey() > records.get(j).getKey()) {
					min = j ;
				}
			}
			Record tmp = new Record(records.get(i));
			records.set(i, records.get(min));
			records.set(min, tmp);
			setChanged();
			notifyObservers(records);
		}
		return records;
	}

	@Override
	public String getName() {
		return "Selection Sort";
	}

}
